package StringMethods;

public class method2 {
    public static void main(String[] args) {
//        print1();
//        extracted();
//        getTimes();
//        phoneSubString();
//        String a = "1234567890";
//        String replace = a.replace("123", "555");
//        System.out.println(replace); // 5554567890
//        spliceFn();
        String s = "192.168.1.1";
        String[] split = s.split("\\."); // 小数点要转义
        for (int i = 0; i < split.length; i++) {
            System.out.println(split[i]);
        }
        System.out.println(s);
    }

    private static void spliceFn() {
        /*
        * 需求 , 切换字符串中的TMD
        * */
        String s = "你好啊,TMD,收到李逵负荆为了让tmd";
        s.replace("TMD", "***");
        System.out.println(s);
    }

    private static void phoneSubString() {
        String s = "1,2,3";
        String s2 = s.substring(2,4); // 包前不包后
        System.out.println(s2);
        /*
        * 手机号 中间加密
        * */
        String s3  = "12345678901";
        String s4 = s3.substring(0,3) + "****" + s3.substring(7);
        System.out.println(s4);
    }

    private static void getTimes() {
        /*
        * 统计字符串里录入的字符的 次数, 只考虑 字母, 区分大小写.
        * */
        String  s = "abcBC+-887";

        int smallCount =0;
        int bigCount =0;
        int shuziCount =0;
        char[] array = s.toCharArray();
        for (int i = 0; i < array.length; i++) {
            if(array[i]>='a' && array[i]<='z' ){
                smallCount+=1;
            }
            if(array[i]>='A' && array[i]<='Z' ){
                bigCount+=1;
            }
            if(array[i]>='0' && array[i]<='9' ){
                shuziCount+=1;
            }
        }
        System.out.println(smallCount);
        System.out.println(bigCount);
        System.out.println(shuziCount);
    }

    private static void extracted() {
        String s = "123";
        for (int i = 0; i < s.length(); i++) {
            System.out.println(s.charAt(i));
        }
    }

    private  static void print1() {
        /*
        * 字符串转 字符数组
        * */
        String s = "123";
        char[] array = s.toCharArray();
        for (int i = 0; i < array.length; i++) {
            System.out.println(array[i]);
        }
    }
}
